﻿using ITXHWEB.Models;
using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Web.Mvc;
using WPFExcelReport;
using WPFExcelReport.Helpers;
using ITXHWEB.Infrastructure;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace ITXHWEB.Controllers
{
    public partial class ABPOSController : ITXController
    {
        [ChildActionOnly]
        public ActionResult SABKTP(string returnUrl)
        {
            ModelState.Clear();
            ViewBag.ReturnUrl = returnUrl;
            MABF.REMARK = INFO;
            return PartialView(MABF);
        }

        [HttpPost]
        [AllowAnonymous]
        [ValidateAntiForgeryToken]
        public ActionResult SABKTP(ABFOLGEModel model, string returnUrl)
        {

            ModelState.Clear();
            MABF.ABPAUF = model.ABPAUF.Trim();
            LOADABKTP(MABF.ABPAUF);
            if (MABF.IsABPReady)
            {
                INFO = "单号扫描正确";
            }
            else
            {
                INFO += model.ABPAUF + "不在有效范围内";
            }
            return RedirectToAction(MAPP, MAPP);
        }
        private void LOADABKTP(string abk)
        {

            dwData = VHP.VABP.TBMain.NewRow();
            dwData["ABPMANDANT"] = app.Mandant;
            dwData["ABPAUFKRS"] = abk.Substring(0, 2);
            dwData["ABPAUFLFD"] = abk.Substring(2, 6);
            dwData["ABPBESCHICH"] = " AND ABPTP>="+ abk.Substring(8, 1)+"000 AND ABPTP <=" + abk.Substring(8, 1)+"999";
            SResult = VHP.VABP.QABKTP(dwData);
            foreach(DataRow row in SResult.Tables[0].Rows)
            {
                ABPOSModel abp = new ABPOSModel();
                abp.ABPAUF = row["ABPAUFKRS"].ToString() + row["ABPAUFLFD"].ToString() + row["ABPAUFPOS"].ToString();
                abp.ART = row["PRART"].ToString();
                abp.VAR = row["PRVAR"].ToString();
                abp.FARBE = row["FARBE"].ToString();
                MABF.ABPS.Add(abp);
            }
            MABF.IsABPReady = true;
        }
    }
}
